package com.dmgo.common;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Created by user on 29.10.2014.
 */


@Entity
@Table(name = "Way", catalog = "mkyong")
public class Way implements java.io.Serializable {

    private int wayId;
    private String wayName;
    private String wayDescription;


    public void setDepo(Depo depo) {
        this.depo = depo;
    }


    //generate link to 2nd table
    //its important that mappedBy parametr was the same as table name
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "way", cascade = CascadeType.ALL)
    public Depo getDepo() {
        return depo;
    }

    private Depo depo;


    public Way(String wayName, String wayDescription) {
        this.wayName = wayName;
        this.wayDescription = wayDescription;
    }


    public Way(int wayId, String wayName, String wayDescription) {
        this.wayId = wayId;
        this.wayName = wayName;
        this.wayDescription = wayDescription;
    }

    public Way() {
    }


    public void setWayId(int wayId) {
        this.wayId = wayId;
    }

    public void setWayName(String wayName) {
        this.wayName = wayName;
    }

    public void setWayDescription(String wayDescription) {
        this.wayDescription = wayDescription;
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "WAY_ID", unique = true, nullable = false)
    public int getWayId() {
        return wayId;
    }

    @Column(name = "WAY_NAME", length = 20)
    public String getWayName() {
        return wayName;
    }

    @Column(name = "WAY_DESCRIPTION", length = 20)
    public String getWayDescription() {
        return wayDescription;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Way Way = (Way) o;

        if (wayId != Way.wayId) return false;
        if (wayDescription != null ? !wayDescription.equals(Way.wayDescription) : Way.wayDescription != null)
            return false;
        if (wayName != null ? !wayName.equals(Way.wayName) : Way.wayName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = wayId;
        result = 31 * result + (wayName != null ? wayName.hashCode() : 0);
        result = 31 * result + (wayDescription != null ? wayDescription.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Way{" +
                "wayId=" + wayId +
                ", wayName='" + wayName + '\'' +
                ", wayDescription='" + wayDescription + '\'' +
                '}';
    }


}
